package oop.java0322;

import java.util.Scanner;

public class Mall {
    String mallName;
    String address;
    Card[] card;
    int count;
    Scanner in = new Scanner(System.in);

    //构造方法
    public Mall() {
        card = new Card[100];
    }

    public Mall(String mallName, String address) {
        card = new Card[100];
        this.mallName = mallName;
        this.address = address;
    }

    //生成card对象的方法
    public Card shengcheng() {
        Card c = new Card();
        return c;
    }

    //添加新会员开卡的方法
    public boolean add(Card c) {
        if (count >= card.length) {
            return false;
        }
        System.out.print("请输入卡号：");
        c.cardNo = in.next();
        for (int i = 0; i < count; i++) {
            if (card[i].cardNo.equals(c.cardNo)) {
                System.out.println("卡号以存在，添加失败!");
                return false;
            }
        }
        System.out.print("请输入姓名：");
        c.name = in.next();
        System.out.print("请输入电话号码：");
        c.telePhone = in.next();
        card[count++] = c;
        System.out.println("添加成功！");
        return true;
    }

    //兑换奖品
    public boolean exchange(String cardNo, int no) {
        for (int i = 0; i < count; i++) {
            if (card[i].cardNo.equals(cardNo)) {
                switch (no) {
                    case 1: {
                        if (card[i].score >= 100) {
                            card[i].score -= 100;
                            System.out.println("成功兑换餐巾纸一包");
                            return true;
                        }
                        System.out.println("积分不足！");
                        return false;
                    }
                    case 2: {
                        if (card[i].score >= 400) {
                            card[i].score -= 400;
                            System.out.println("成功兑换剃须刀一把");
                            return true;
                        }
                        System.out.println("积分不足！");
                        return false;
                    }
                    case 3: {
                        if (card[i].score >= 1000) {
                            card[i].score -= 1000;
                            System.out.println("成功兑换炒锅一个");
                            return true;
                        }
                        System.out.println("积分不足！");
                        return false;
                    }
                    default: {
                        break;
                    }
                }
            }
        }
        System.out.println("账号不存在！");
        return false;
    }

    //增加积分
    public boolean increaseScore(String cardNo, int score) {
        for (int i = 0; i < count; i++) {
            if (card[i].cardNo.equals(cardNo)) {
                card[i].score += score;
                System.out.println("操作成功！");
                return true;
            }
        }
        System.out.println("会员号不存在！");
        return false;
    }

    //查看指定会员信息
    public boolean showInfo(String cardNo) {
        for (int i = 0; i < count; i++) {
            if (card[i].cardNo.equals(cardNo)) {
                System.out.println("卡号：" + card[i].cardNo);
                System.out.println("持卡人姓名：" + card[i].name);
                System.out.println("联系方式：" + card[i].telePhone);
                System.out.println("积分：" + card[i].score + "分");
                return true;
            }
        }
        System.out.println("会员号不存在！");
        return false;
    }

    //展示商城信息
    public void showMall() {
        System.out.println("name:" + mallName);
        System.out.println("address:" + address);
        System.out.println("会员数量:" + count);
    }
}
